package com.jt.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.jt.mapper.UserMapper;
import com.jt.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service

public class UserServiceImpl implements UserService{

    @Autowired
    private UserMapper userMapper;


    @Override
    public List<User> findAll() {
        return userMapper.selectList(null);
    }

    @Override
    public User getById(Integer id) {
        return userMapper.selectById(id);
    }

    @Override
    public List<User> getByUs(User us) {
        QueryWrapper<User> wrapper = new QueryWrapper<>(us);
        return userMapper.selectList(wrapper);
    }

    @Override
    public List<User> getUser(String name) {
        QueryWrapper<User> wrapper = new QueryWrapper<User>();
         wrapper.like("name",name);
        return userMapper.selectList(wrapper);
    }

    @Override
    public int removeuser(User user) {
        return userMapper.delete(new QueryWrapper<>(user));
    }

    @Override
    public int removeNS(String name, String sex) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("name",name);
        wrapper.eq("sex",sex);
        return userMapper.delete(wrapper);
    }

    @Override
    public int deleteById(int id) {
        return userMapper.deleteById(id);
    }

    @Override
    public void saveUser(User user) {
         userMapper.insert(user);
    }

    @Override
    public void updateByUser(User user) {
        userMapper.updateById(user);
    }
}
